//
//  DetailCell.m
//  BabyBedtimeStory
//
//  Created by qianfeng on 15-7-2.
//  Copyright (c) 2015年 张鹏毅. All rights reserved.
//

#import "DetailCell.h"
#import "UIImageView+WebCache.h"

@implementation DetailCell

- (void)awakeFromNib {
    // Initialization code
}

-(void)showWithModel:(StoryModel *)model{
    self.modelA = model;
    self.titleLabel.font = [UIFont fontWithName:@"Didot" size:13];
    self.titleLabel.text = model.title;
    self.play_numLabel.font = [UIFont fontWithName:@"Didot" size:13];
    self.play_numLabel.text = [NSString stringWithFormat:@"播放次数%@次 %@",model.play_num,model.duration];
}

-(void)showWithModelImage:(StoryModel *)model{
    self.modelB = model;
    [self.image_urlImageView sd_setImageWithURL:[NSURL URLWithString:model.image_url] placeholderImage:[UIImage imageNamed:@"yujiazai"]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (IBAction)downloadClick:(UIButton *)sender {
    StoryModel *model = [[StoryModel alloc]init];
    model = self.modelA;
    model.image_url = self.modelB.image_url;
    model.album_id = self.modelB.album_title;
    [[DBManager sharedManager]insertModel:model recordType:kDownloads];
    BOOL isYes = [[DBManager sharedManager]isExistAppForAppId:model.id
                                                   recordType:kDownloads];
    if (isYes) {
        NSString *str = @"收藏成功";
        [self creatAlter:str];
    }else{
        NSString *str = @"收藏失败";
        [self creatAlter:str];
    }
}

-(void)creatAlter:(NSString *)str{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [[[[UIApplication sharedApplication]keyWindow]rootViewController] presentViewController:alert animated:YES completion:nil];
}

@end
